# mods/你的模组名.py
from SuperQQBot import User, Intents, MessageSendReceiveAPI # 导入要替换的函数
import warnings
from SuperQQBot.core.Error import CompatibilityWillBeUnSuppose

TYPES = 'test'
"""TYPES的内容大小写不敏感，但一定要定义，并且类型只能为字符串
test:表示该模组还在测试中，提供测试内容
trans_old:提供新旧功能转换
other:表示还没有包含在以上几类中"""

def setup():
    # 动态添加 old_flags 属性到 Intents 类
    Intents.old_flags = {
        "public_messages": 'GROUP_AND_C2C_EVENT',
        'public_guild_messages':'PUBLIC_GUILD_MESSAGES'
    }

    # 重写Intents的__init__类
    def new_init(self, **kwargs: bool):
        self.value = Intents.DEFAULT_VALUE
        self.intents = {flag: False for flag in Intents.VALID_FLAGS}
        for key, value in kwargs.items():
            if key in Intents.old_flags:
                (warnings
                 .warn(CompatibilityWillBeUnSuppose(key, Intents.old_flags[key])))
                self.intents[Intents.old_flags[key]] = value
                continue
            if key not in Intents.VALID_FLAGS:
                raise TypeError(f"{key!r} 是无效的标志名称。")
            self.intents[key] = value
        self._update_bitwise_value()
    # 动态替换__init__
    Intents.__init__ = new_init

    # 定义一个name属性
    def name(self):
        (warnings
         .warn(CompatibilityWillBeUnSuppose('self.robot.name', 'self.robot.username')))
        return self.username
    # 动态添加 name 属性到 User 类
    User.name = property(name)

    # 希望加入的函数
    async def post_message(self, **kwargs):
        (warnings
         .warn(CompatibilityWillBeUnSuppose('BotSendReceiveAPI.post_message', 'BotSendReceiveAPI.post_channel_message')))
        return await self.post_channel_messages(**kwargs)
    # 动态的创建方法（类似于替换）
    MessageSendReceiveAPI.post_message = post_message
# 执行 setup 函数来应用更改
# 这步可写可不写
setup()